package com.har.modules.web.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.har.common.exception.RRException;
import com.har.common.utils.StringUtil;
import com.har.modules.web.dao.LoanDao;
import com.har.modules.web.entity.CommonEntity;
import com.har.modules.web.entity.LoanEntity;
import com.har.modules.web.service.LoanService;
import org.springframework.stereotype.Service;

@Service("loanService")
public class LoanServiceImpl extends ServiceImpl<LoanDao,LoanEntity> implements LoanService {


    @Override
    public CommonEntity selectById(Long id) {
        EntityWrapper<LoanEntity> ew=new EntityWrapper<>();
        if(!StringUtil.isEmpty(String.valueOf(id))){
            ew.eq("id",id);
            ew.eq("status",1);
        }
        LoanEntity loanEntity=this.selectOne(ew);
        if(null==loanEntity){
            throw new RRException("id不存在，查询失败");
        }
        CommonEntity commonEntity=new CommonEntity();
        commonEntity.setId(loanEntity.getId());
        commonEntity.setImage(loanEntity.getImage());
        commonEntity.setProductDesc(loanEntity.getProductDesc());
        commonEntity.setProductName(loanEntity.getProductName());
        commonEntity.setProductDetails(loanEntity.getProductDetails());
        String [] type=new String[2];
        if(!StringUtil.isEmpty(loanEntity.getType())){
            type[0]=loanEntity.getType();
        }
        if(!StringUtil.isEmpty(loanEntity.getProductName())){
           type[1]=loanEntity.getProductName();
        }
        commonEntity.setPath(type);
        return commonEntity;
    }
}
